package com.tmeone.erpone.controller;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.tmeone.erpone.entity.TOrder;
import com.tmeone.erpone.entity.TShipping;
import com.tmeone.erpone.service.ITOrderService;
import com.tmeone.erpone.service.ITShippingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tmone
 * @since 2021-04-20
 */
@RestController
public class TShippingController {
@Autowired
private ITShippingService itShippingService;

@Autowired
private ITOrderService orderService;


    @RequestMapping(value = "/shipping", method = RequestMethod.POST)
    public void insertRole(@RequestBody TShipping tShipping) {
        tShipping.setId(UUID.randomUUID().toString().replace("-","").substring(0,6));
        tShipping.setStartPlace("起始地点");
        tShipping.setEndPlace("到达地点");
        tShipping.setDistance("距离");
        tShipping.setCompanyId("2222");
        itShippingService.save(tShipping);
        // 更改订单状态
        UpdateWrapper<TOrder> updateWrapper = new UpdateWrapper();
        updateWrapper.set("order_status",3);
        updateWrapper.eq("order_id",tShipping.getOrderNum());
        orderService.update(updateWrapper);
    }

}
